package com.lovo.movie.controller;

import com.lovo.dto.TicketVo;
import com.lovo.movie.dao.ITicketDao;
import com.lovo.movie.entity.TicketEntity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("movie")
@RestController
public class MovieController {
    @Autowired
    private ITicketDao ticketDao;
   @GetMapping("updateMovieNum/{movieNumber}/{num}")
    public  boolean updateMovieNum(@PathVariable("movieNumber")String movieNumber,
                                   @PathVariable("num")int num){
    TicketEntity ticketEntity= ticketDao.findDistinctByMovieNumber(movieNumber);
    ticketEntity.setSellNum(ticketEntity.getSellNum()+num);
       ticketEntity =ticketDao.save(ticketEntity);
       if(ticketEntity!=null){
           return true;
       }
       return  false;
    }

    @PostMapping("updateMovieNum")
    public  boolean updateMovieNumPost(@RequestBody TicketVo ticketVo){
        TicketEntity ticketEntity= ticketDao.findDistinctByMovieNumber(ticketVo.getMovieNumber());
        ticketEntity.setSellNum(ticketEntity.getSellNum()+ticketVo.getNum());
        ticketEntity =ticketDao.save(ticketEntity);
        if(ticketEntity!=null){
            return true;
        }
        return  false;
    }
}
